<include file="Common/common" />
<?php $statusArr = array('0'=>'等待上传凭证','1'=>'等待审核','2'=>'完成'); ?>

<body>
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<br>
			<div style="overflow-x: auto;">
				<table class="layui-table"  style=" color: rgb(240,222,112);">
					<thead  >
							<tr style="background: rgb(57,61,73)">
								<th>积分数量</th>
								<th>折扣</th>
								<th>需要支付USDT数量</th>
								<!-- <th>钱包地址</th> -->
								<th>操作</th>
							</tr> 
						</thead>
						<tbody>
							<foreach name="sellcenterList" item="vo">
								<tr style="background: #7d7d7d;color:rgb(240,222,112);">
									<td>{$vo['num']}</td>
									<td>{$vo['discount']}</td>
									<td>{$vo['num_usdt']}</td>
									<!-- <td>{$vo['wallet_address']}</td> -->
									<td>
										<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" onclick="func_buy(this,{$vo['id']})" >购买</button>
									</td>
								</tr>
							</foreach>
						</tbody>
				</table>
			</div>

			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			  	<legend style="color: rgb(240,222,112);">订单</legend>
			</fieldset>
			<div style="overflow-x: auto;">
				<table class="layui-table"  style=" color: rgb(240,222,112);" >
					<thead>
							<tr style="background: rgb(57,61,73)">
								<th>编号</th>
								<th>积分数量</th>
								<th>折扣</th>
								<th>需要支付USDT数量</th>
								<th>钱包地址</th>
								<th>购买人账户</th>
								<th>状态</th>
								<th>退回留言</th>
								<th>操作</th>
							</tr> 
						</thead>
						<tbody id="order-body">
							<foreach name="ordercenterList" item="vo">
								<tr style="background: #7d7d7d;color:rgb(240,222,112);">
									<td>{$vo['id']}</td>
									<td>{$vo['num']}</td>
									<td>{$vo['discount']}</td>
									<td>{$vo['num_usdt']}</td>
									<td>
										<if condition="$vo['status'] eq 2">
											**********
										<else/>
											{$vo['wallet_address']}
										</if>
									</td>
									<td>{$userInfo['account']}</td>
									<td>{$statusArr[$vo['status']]}</td>
									<td style="color:red;">{$vo['remark']}</td>
									<td>
										<if condition="$vo['status'] eq 0 ">
											<div class="layui-btn-group">
												<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn layui-btn-sm" onclick="func_show(this,{$vo['id']})" >添加凭证</button>
												<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn layui-btn-sm" onclick="func_finish(this,{$vo['id']})" >确认提交</button>
											</div>
										</if>
									</td>
								</tr>
							</foreach>
						</tbody>
				</table>
			</div>
			<!-- <div class="green-black">{$page}</div> -->
		</div>
	</div>
</body>
<script type="text/javascript">
	var useraccount = {$userInfo['account']};

	// 确认
	function func_finish(obj,id){
		layer.confirm('<span style="color: rgb(240,222,112);">确认USDT已付款，凭证已上传，确认提交，审核通过后所购积分将转至购买人账户</span>',{offset:'none'},function(index){
			$.ajax({
	            type: "post",
	            url: "{:U('Order/ctrl_buyCenterFinish')}",
	            data: {id:id},
	            dataType: "json",
	            success: function(rtJson){
	            	if (rtJson.code == 1) {
	            		setTimeout(function(){location.reload();}, 1000);
	            	}
                    layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
            		
	            }
	        });
		});
	}

	// 查看、上传凭证
	function func_show(obj,id){
		
		layer.open({
			type: 2,
			title: '编号：'+id,
			shadeClose: true,
			shade: 0.8,
			scrollbar: false,
			area: ['100%', '100%'],
			content: "/Order/showcenter?id="+id, //iframe的url
			
		});
	}


	// 购买
	function func_buy(obj,id){
		layer.confirm('确定购买？',{offset:'none'},function(index){
			$.ajax({
	            type: "post",
	            url: "{:U('Order/ctrl_buyCenter')}",
	            data: {id:id},
	            dataType: "json",
	            success: function(rtJson){
	            	if (rtJson.code == 1) {
	            		// console.log(rtJson.data);
	            		// var innerTD = '';
               //      	innerTD  += "<tr><td>"+rtJson.res+"</td>"+
               //      		"<td>"+rtJson.data.num+"</td>"+
               //      		"<td>"+rtJson.data.discount+"</td>"+
               //      		"<td>"+rtJson.data.num_usdt+"/"+rtJson.data.wallet_address+"</td>"+
               //      		"<td>"+useraccount+"</td>"+
               //      		"<td>等待上传凭证</td>"+
               //      		"<td><div class='layui-btn-group'><button class='layui-btn layui-btn-sm' onclick='func_show(this,"+rtJson.res+")' >查看，上传凭证</button><button class='layui-btn layui-btn-sm' onclick='func_finish(this,"+rtJson.res+")' >确认</button></div></td></tr>";
               //      	$(innerTD).prependTo('#order-body');
                    	layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
            			setTimeout(function(){location.reload();}, 1000);
	            	}else{
	            		layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
	            	}
            		// setTimeout(function(){location.reload();}, 1000);
	            }
	        });
		});
	}
</script>
<include file="Common/footer" />